package com.qcby.onlinelearningplatform.Controller;

import com.qcby.onlinelearningplatform.Common.R;
import com.qcby.onlinelearningplatform.Common.ResultCommon;
import com.qcby.onlinelearningplatform.Entity.*;
import com.qcby.onlinelearningplatform.Service.RelService;
import com.qcby.onlinelearningplatform.Service.StudentService;
import com.qcby.onlinelearningplatform.Service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;


@Controller
@Slf4j
@RequestMapping("/teacher")
@Api(tags = "教师接口信息")
public class TeacherController {

    @Autowired
    public TeacherService teacherService;

    @Autowired
    public RelService relService;

    @ResponseBody
    @GetMapping("/teacherChannel")
    @ApiOperation(value = "后台栏目展示")
    public ResultCommon channel(){
        List<TeacherChannel> teacherChannnel = teacherService.teacherChannle();
        System.out.println(teacherChannnel);
        if (teacherChannnel.size() == 0){
            return ResultCommon.error("查询栏目失败");
        }
        return ResultCommon.success("查询栏目成功",teacherChannnel);
    }

    @ResponseBody
    @PostMapping("/teacherState")
    @ApiOperation(value = "教师状态管理展示")
    @ApiImplicitParams({
                    @ApiImplicitParam(name = "pageSize",value = "每一页的数量",required = true),
            @ApiImplicitParam(name = "pageIndex",value = "页码",required = true)
            })
    public ResultCommon state(Integer pageSize,Integer pageIndex){
        List<Teacher> state1 = teacherService.teacherState(pageSize,pageIndex);
        System.out.println(state1);
        if (state1.size() == 0){
            return ResultCommon.error("查询状态信息失败");
        }
        return ResultCommon.success("查询状态信息成功",state1);
    }

    @ResponseBody
    @PostMapping("/studentInfo")
    @ApiOperation(value = "学生信息管理展示")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize",value = "每一页的数量",required = true),
            @ApiImplicitParam(name = "pageIndex",value = "页码",required = true)
    })
    public ResultCommon studentInfo(Integer pageSize,Integer pageIndex){
        List<Student> students = teacherService.studentInfo(pageSize,pageIndex);
        System.out.println(students);
        if (students.size() == 0){
            return ResultCommon.error("查询学生信息失败");
        }
        return ResultCommon.success("查询学生信息成功",students);
    }

    @ResponseBody
    @GetMapping("/studentAndTeacher")
    @ApiOperation(value = "学生全部信息管理展示")
    public ResultCommon studentAndTeacher(Integer pageSize,Integer pageIndex){
        List<Teacher> teachers = teacherService.studentFindTeacher(pageSize,pageIndex);
        System.out.println(teachers);
        if (teachers.size() == 0){
            return ResultCommon.error("查询全部学生信息失败");
        }
        return ResultCommon.success("查询全部学生信息成功",teachers);
    }


    @ResponseBody
    @GetMapping("/findNameSno")
    @ApiOperation(value = "学生全部信息搜索")
    public ResultCommon findNameSno(Student student){
         List<Student> students =  teacherService.findNameSno(student);
        System.out.println(students);
        if (students.size() == 0){
            return ResultCommon.error("搜索学生信息失败");
        }
        return ResultCommon.success("搜索学生信息成功",students);
    }


    @ResponseBody
    @PostMapping("/findNameSno")
    @ApiOperation(value = "修改学生信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "s_id",value = "id",required = true),
    })
    public ResultCommon updateStudent(Student student){
        int res =  teacherService.updateStudent(student);

        if (res == 0){
            return ResultCommon.error("修改学生信息失败");
        }
        return ResultCommon.success("修改学生信息成功",res);
    }


    @ResponseBody
    @GetMapping("/showHomework")
    @ApiOperation(value = "查看学生作业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "id",required = true),
    })
    public ResultCommon showHomework(Integer id){
        List<StuHomework> stuHomeworks =  teacherService.showHomework(id);

        if (stuHomeworks.size() == 0){
            return ResultCommon.error("该作业同学们还没有完成");
        }
        return ResultCommon.success("作业查询成功，请查看",stuHomeworks);
    }

    @ResponseBody
    @PostMapping("/insertHomework")
    @ApiOperation(value = "添加作业")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id",value = "id",required = true),
//    })
    public ResultCommon insertHomework(HomeWork homeWork){
        homeWork.setWorkTime(new Date());
        int res = teacherService.insertHomework(homeWork);

        if (res== 0){
            return ResultCommon.error("添加失败");
        }
        return ResultCommon.success("添加成功",homeWork);
    }















}
